//
//  ShopDetailViewController.m
//  OrderSeat
//
//  Created by wangwei on 13-10-8.
//  Copyright (c) 2013年 wangwei. All rights reserved.
//

#import "ShopDetailViewController.h"
#import "ShopHomeViewController.h"

@implementation ShopDetailViewController

- (id)initWithShopId:(NSString*)shopId
{
    self = [super initWithNibClass:[ShopDetailViewController class]];
    if (self) {
        _shopId = shopId;
        _dataSource = [[ShopDetailDataSource alloc] initWithVC:self];
        [_dataSource fetchShopDetailInfo];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupUI];
}

- (void)setupUI
{
    [self createLeftButton];
    
    [self setNavigationTitle:@"商家详情"];

    [UIView drawBorders:@[_firstView, _secondView, _lastView]];
    [_theScrollview autoContentHeight];
}

- (void)leftButtonClick:(id)sender
{
    [self pushOrPopViewController:[ShopHomeViewController class]];
}

- (void)setFormValues:(NSDictionary*)data
{
    _shopNameLabel.text = [data objectForKey:@"name"];
    _telLabel.text = [data objectForKey:@"tel"];
    _addressLabel.text = [data objectForKey:@"xianqu"];
    _caixiLabel.text = [data objectForKey:@"caixi"];
    _jieshaoLabel.text = [data objectForKey:@"jieshao"];
    _workTimeLabel.text = [data objectForKey:@"yingye_time"];
    _priceLabel.text = [data objectForKey:@"renjun"];
    _youhuiLabel.text = [data objectForKey:@"zhekou"];
    _renqiLabel.text = [[data objectForKey:@"rq"] stringValue];
    _luxianLabel.text = [data objectForKey:@"gongjiao"];
    _orderLabel.text = [[data objectForKey:@"dingdanshu"] stringValue];
    _commentsLabel.text = [[data objectForKey:@"pinglunshu"] stringValue];
    
    [_priceLabel autoWidthForSingleLine];
    _unitLabel.left = _priceLabel.right;
}
@end

//=========================================================================================
#pragma ===================数据源类实现======================================================
//=========================================================================================

@implementation ShopDetailDataSource

- (id)initWithVC:(id)viewController
{
    self = [super init];
    if (self) {
        self.viewController = viewController;
    }
    return self;
}

- (void)fetchShopDetailInfo
{
    [SVProgressHUD show];
    NSString *shopId = self.viewController.shopId;
    NSString *url = [NSString stringWithFormat:API_SHOP_DETAIL_INFO, shopId];
    [self get:url];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    [SVProgressHUD dismiss];
    NSDictionary *json = [request.responseString JSONValue];
    NSDictionary *data = [json objectForKey:@"data"];
    [self.viewController setFormValues:data];
}

@end













